{extend name="common/base" /}
{block name="title"}添加商品{/block}
{block name="main"}
<script src="/ad/js/g_add/g_add.js"></script>
     <!-- Navigation -->
	   <div id="page-wrapper">
        <div class="col-md-12 graphs">
		<div class="xs">
  	    <h3>{$res['goods_id']?"编辑商品":"添加商品"}</h3>
        <div class="well1 white" style="float: left;">
        <h5 ><a href="{:url('/admin/Goods/g_list')}"><span class="label label-success">返回列表</span></a></h5>
        {notempty name="res['goods_id']"}
          <h5 ><a href="{:url('/admin/Goods/g_add',array('goods_id'=>$res['goods_id']))}"><span class="label label-success">基本参数</span></a></h5>
          <h5 ><a href="{:url('/admin/Goods/g_add_details',array('id'=>$res['goods_id']))}"><span class="label label-success">商品详情</span></a></h5>
          <h5 ><a href="{:url('/admin/Goods/g_add_tu',array('id'=>$res['goods_id']))}"><span class="label label-success">商品图片</span></a></h5>
        {/notempty}
        </div>
  	    <div class="well1 white">
        <form class="form-floating" id="g_add" novalidate="novalidate" ng-submit="submit()" action="{:url('Goods/dog_add')}" method ='post' enctype="multipart/form-data">
          <fieldset>
            <div class="form-group">
              <label class="control-label">商品名称</label>
              <input name="goods_title" type="text" class="form-control1 goods_title" value="{$res['goods_title']?$res['goods_title']:''}" required="">
              <input type="hidden" name="goods_id" value="{$res['goods_id']?$res['goods_id']:''}">
            </div>
            <div class="form-group">
              <label class="control-label">商品品牌</label>
              <input name="goods_brand" type="text" class="form-control1 goods_brand"  value="{$res['goods_brand']?$res['goods_brand']:''}" required="">
            </div>
            <div class="form-group filled">
              <label class="control-label">商品分类</label>
              <select class="form-control1 goods_a_type" name="goods_a_type">
              {volist name="g_type" id="gty"}
                <option value="{$gty['goods_type_id']}" {$res['goods_a_type']?($res['goods_a_type'] == $gty["goods_type_id"]?"selected":""):""}>{$gty.goods_type_name}</option>
            {/volist}
              </select>
              <label class="control-label">二级分类</label>
              <select class="form-control1 goods_b_type"  name="goods_b_type">
                <option value="{$p_type['goods_type_id']?$p_type['goods_type_id']:''}">{$p_type['goods_type_name']?$p_type['goods_type_name']:""}</option>
              </select>
            </div>
            <div class="form-group">
              <label class="control-label">商品价格</label>
              <input name="goods_price" type="text" class="form-control1 goods_price"  value="{$res['goods_price']?$res['goods_price']:''}" required="" >
            </div>
            <div class="form-group">
              <label class="control-label">商品库存</label>
              <input name="goods_repertory" type="text" class="form-control1 goods_repertory" ng-model="model.name" value="{$res['goods_repertory']?$res['goods_repertory']:''}" required="" >
            </div>
            <div class="form-group filled">
              <label class="control-label">商品状态</label>
              <select class="form-control1 goods_isactivity" required="" name="goods_isactivity">
                <option value="0" {$res["goods_isactivity"]?"":"selected"} selected>常规商品</option>
                <option value="1" {$res["goods_isactivity"]?"selected":""}>活动商品</option>
              </select>
            </div>
			<div class="form-group">
              <label class="control-label">商品图片</label>
              <input  type="file" ng-model="model.file" required="" id="exampleInputFile">
			<!-- 显示图片的地方 -->
			<div id="destination" style="margin-top:10px;">
      <input type="hidden" name="goods_image" value="{$res['goods_image']?$res['goods_image']:''}">
      <img src="{$res['goods_image']?$res['goods_image']:''}" style="width:100px;"></div>

            </div>
            <div class="form-group">
              <button type="button" class="btn btn-primary">{$res['goods_id']?"提交":"下一步"}</button>
              <button type="reset" class="btn btn-default">重置</button>
            </div>
          </fieldset>
        </form>
      </div>
    </div>

	    <script type="text/javascript">
			document.getElementById('exampleInputFile').addEventListener('change', function() {
				var file;
				var destination = document.getElementById('destination');
				destination.innerHTML = '';

				// 循环用户多选的文件
				for(var x = 0, xlen = this.files.length; x < xlen; x++) {
					file = this.files[x];
                    if(file.type.indexOf('image') != -1) { // 非常简单的交验

                        var reader = new FileReader();

                        reader.onload = function(e) {
                            var img = new Image();
                            var input = document.createElement("input");
                            input.type = 'hidden';
                            input.value = e.target.result;
                            input.name = 'goods_image';
                            img.src = e.target.result; // 显示图片的地方
                            img.width = 100;
                            destination.appendChild(img);
                            destination.appendChild(input);
						};

						reader.readAsDataURL(file);
					}
				}
			});
		//隐藏提示消息
		/*window.onload = function(){
            setInterval(function(){
    			$("#jg").fadeOut(1000);
    		}, 3000);
		}*/
		</script>


		{/block}



